package leetcode3;
import java.util.*;
public class Day21 {
    public int hIndex(int[] citations) {
        Arrays.sort(citations);
        int h=0,i=citations.length-1;
        while(i>=0 && citations[i]>h) {
            h++;
            i--;
        }
        return h;
    }



    public ListNode detectCycle(ListNode head) {
        if(head==null) return head;
        ListNode slow = head;
        ListNode fast = head;
        while(fast!=null && fast.next!=null) {
            slow = slow.next;
            fast = fast.next.next;
            if(slow==fast) {
                fast=head;
                while(fast!=slow) {
                    fast=fast.next;
                    slow=slow.next;
                }
                return fast;
            }
        }
        return null;
    }
}
